def prostoe(s):
    for i in range(2,int(s**0.5)+1):
        if (s%i==0):
            break
    else:
        return False
        
A=input().split()
x=0
s=0
b=0
slovar=["zero", "one","two","three","four","five","six","seven","eight","nine"]
if len(A)==3:
    for i in range(3):
        if A[i] not in slovar:
            print("Wrong input")
            b+=1
            break
else:
    print("Wrong input")
    
if len(A)==3 and b<1:
    for i in range(10):
        if A[0]==slovar[i]:
            s+=i*100
        if A[1]==slovar[i]:
            s+=i*10
        if A[2]==slovar[i]:
            s+=i
    prostoe(s)
    while True:
        if prostoe(s-x)==False:
            print(s-x)
            break
        if prostoe(s+x)==False:
            print(s+x)
            break
        x+=1
